<?php
    session_start();
    include('conect_db.php');
    
    function  loggin($u, $p){//conect te user to the system.
        $link = conect_db();
        $query = sprintf("SELECT * FROM usuario WHERE usuario = '%s' AND clave_usuario = MD5('%s') LIMIT 1 ", $u, $p);
        echo "<br />$query";
        $result = mysql_query($query, $link);
        $cant = mysql_num_rows($result); 
        if( mysql_num_rows($result)== 0 ){
            return false;
        }else{
            return true;
        }
    }

    function disconnect(){
        $old_user = $_SESSION['user'];//to probe if the user was conected
        unset($_SESSION['user']);
        $result_dest = session_destroy();
        if( !( empty( $old_user ) ) ){
            if($result_dest){
                //If was conected... then now is disconected.
                echo "logged out";
            }else{
                //If was conected, and can't logged out.
                echo "Could not log you out";
            }
        }else{
            //If the user was not logged but somehow has been acces to this.
            echo "You are not logged in, and so have not been logged out";
        }
    }

?>
